namespace SuppKids.Migrator.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class SchemaChanges : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.ProductConsumptionValues", "Ingredient_Id", "dbo.Ingredients");
            DropForeignKey("dbo.Ingredients", "Dish_Id", "dbo.Dishes");
            DropForeignKey("dbo.ProductAtStorages", "Product_Id", "dbo.Products");
            DropForeignKey("dbo.Ingredients", "Product_Id", "dbo.Products");
            DropIndex("dbo.ProductConsumptionValues", new[] { "Ingredient_Id" });
            DropIndex("dbo.Ingredients", new[] { "Dish_Id" });
            DropIndex("dbo.ProductAtStorages", new[] { "Product_Id" });
            DropIndex("dbo.Ingredients", new[] { "Product_Id" });
            CreateTable(
                "dbo.Groups",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 255),
                    })
                .PrimaryKey(t => t.Id);
            
            AddColumn("dbo.ProductConsumptionValues", "Group_Id", c => c.Int(nullable: false));
            AlterColumn("dbo.Ingredients", "Dish_Id", c => c.Int(nullable: false));
            AlterColumn("dbo.Ingredients", "Product_Id", c => c.Int(nullable: false));
            AlterColumn("dbo.ProductAtStorages", "Bill", c => c.String(nullable: false, maxLength: 4000));
            AlterColumn("dbo.ProductAtStorages", "Supplier", c => c.String(nullable: false, maxLength: 4000));
            AlterColumn("dbo.ProductAtStorages", "Recipient", c => c.String(nullable: false, maxLength: 4000));
            AlterColumn("dbo.ProductAtStorages", "Product_Id", c => c.Int(nullable: false));
            CreateIndex("dbo.ProductConsumptionValues", "Group_Id");
            CreateIndex("dbo.ProductConsumptionValues", "Ingredient_Id");
            CreateIndex("dbo.Ingredients", "Dish_Id");
            CreateIndex("dbo.ProductAtStorages", "Product_Id");
            CreateIndex("dbo.Ingredients", "Product_Id");
            AddForeignKey("dbo.ProductConsumptionValues", "Group_Id", "dbo.Groups", "Id", cascadeDelete: true);
            AddForeignKey("dbo.ProductConsumptionValues", "Ingredient_Id", "dbo.Ingredients", "Id");
            AddForeignKey("dbo.Ingredients", "Dish_Id", "dbo.Dishes", "Id", cascadeDelete: true);
            AddForeignKey("dbo.ProductAtStorages", "Product_Id", "dbo.Products", "Id", cascadeDelete: true);
            AddForeignKey("dbo.Ingredients", "Product_Id", "dbo.Products", "Id", cascadeDelete: true);
            DropColumn("dbo.ProductConsumptionValues", "Group");
        }
        
        public override void Down()
        {
            AddColumn("dbo.ProductConsumptionValues", "Group", c => c.Int(nullable: false));
            DropForeignKey("dbo.Ingredients", "Product_Id", "dbo.Products");
            DropForeignKey("dbo.ProductAtStorages", "Product_Id", "dbo.Products");
            DropForeignKey("dbo.Ingredients", "Dish_Id", "dbo.Dishes");
            DropForeignKey("dbo.ProductConsumptionValues", "Ingredient_Id", "dbo.Ingredients");
            DropForeignKey("dbo.ProductConsumptionValues", "Group_Id", "dbo.Groups");
            DropIndex("dbo.Ingredients", new[] { "Product_Id" });
            DropIndex("dbo.ProductAtStorages", new[] { "Product_Id" });
            DropIndex("dbo.Ingredients", new[] { "Dish_Id" });
            DropIndex("dbo.ProductConsumptionValues", new[] { "Ingredient_Id" });
            DropIndex("dbo.ProductConsumptionValues", new[] { "Group_Id" });
            AlterColumn("dbo.ProductAtStorages", "Product_Id", c => c.Int());
            AlterColumn("dbo.ProductAtStorages", "Recipient", c => c.String(maxLength: 4000));
            AlterColumn("dbo.ProductAtStorages", "Supplier", c => c.String(maxLength: 4000));
            AlterColumn("dbo.ProductAtStorages", "Bill", c => c.String(maxLength: 4000));
            AlterColumn("dbo.Ingredients", "Product_Id", c => c.Int());
            AlterColumn("dbo.Ingredients", "Dish_Id", c => c.Int());
            DropColumn("dbo.ProductConsumptionValues", "Group_Id");
            DropTable("dbo.Groups");
            CreateIndex("dbo.Ingredients", "Product_Id");
            CreateIndex("dbo.ProductAtStorages", "Product_Id");
            CreateIndex("dbo.Ingredients", "Dish_Id");
            CreateIndex("dbo.ProductConsumptionValues", "Ingredient_Id");
            AddForeignKey("dbo.Ingredients", "Product_Id", "dbo.Products", "Id");
            AddForeignKey("dbo.ProductAtStorages", "Product_Id", "dbo.Products", "Id");
            AddForeignKey("dbo.Ingredients", "Dish_Id", "dbo.Dishes", "Id");
            AddForeignKey("dbo.ProductConsumptionValues", "Ingredient_Id", "dbo.Ingredients", "Id");
        }
    }
}
